// .cpp : implementation file
//

#include "stdafx.h"
#include "GreenBrowser.h"
#include "Resourcebar.h"
#include "mainfrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//#pragma optimize( "s", on )


/////////////////////////////////////////////////////////////////////////////
// CResourcebarTree

CResourcebar::CResourcebar()
{
}

CResourcebar::~CResourcebar()
{
}



/////////////////////////////////////////////////////////////////////////////
// CHistoryTree message handlers

LPCTSTR CResourcebar::GetTitle()
{
	LOADSTR(strTitle ,IDS_TITLE_RESOURCE);
	return (LPCTSTR)strTitle;
}

BOOL CResourcebar::Initialize()
{
    HINSTANCE hInstance = AfxGetResourceHandle();
    ASSERT(hInstance != NULL);

    CString strResourceURL;
    BOOL bRetVal = TRUE;
	LPTSTR lpszModule = NULL;
	try
	{
		 lpszModule = new TCHAR[_MAX_PATH];
	}
	catch(...)
	{
		return FALSE;
	}

    if (GetModuleFileName(hInstance, lpszModule, _MAX_PATH))
    {
		//check if resource.htm exists
		CString strSearchRes(lpszModule);
		int i = strSearchRes.ReverseFind(PATH_DELIMITER_CHAR);
		strSearchRes = strSearchRes.Left(i+1);
		strSearchRes += PATH_ResourcePage;
		//OFSTRUCT fst;
		//if(OpenFile(strSearchRes,&fst ,OF_EXIST)!=HFILE_ERROR)
		if(CDiskIO::PathExists(strSearchRes))
		{
			m_wndResource.Navigate(strSearchRes, 0, 0, 0,NULL);
		}
		else
		{
			m_wndResource.Navigate(TEXT_BlankAddress, 0, 0, 0,NULL);
		}
    }
    else
	{
       bRetVal = FALSE;
	}

    delete [] lpszModule;
    return bRetVal;
}

BOOL CResourcebar::Create(CWnd* pParent)
{
	m_wndResource.Create(NULL, TEXT_Empty, WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN, CRect(0,0,0,0), pParent, IDS_TITLE_RESOURCE,NULL);
	return TRUE;
}

CWnd* CResourcebar::GetWindow()
{
	return (CWnd*)&m_wndResource;
}

void CResourcebar::Destroy()
{
	return;
}

BOOL CResourcebar::Update(int nLevel)
{
	return TRUE;
}

//#pragma optimize( "s", off)
